package it.koutifaris.travianmap.view.villagedetails;

import it.koutifaris.travianmap.R;
import it.koutifaris.travianmap.model.Tribe;
import it.koutifaris.travianmap.ui.TribeResourceMapper;
import it.koutifaris.travianmap.view.villagedetails.VillageDetailsDialog.VillageDetailsView;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

class VillageDetailsViewImpl implements VillageDetailsView {

	private final View root;
	private final TribeResourceMapper resourceMapper;

	public VillageDetailsViewImpl(View root) {
		this.root = root;
		resourceMapper = new TribeResourceMapper();
	}

	@Override
	public void setVillageName(String villageName) {
		getVillageView().setText(villageName);
	}

	@Override
	public void setPopulation(int population) {
		getPopulationView().setText(Integer.toString(population));
	}

	@Override
	public void setPlayerName(String playerName) {
		getOwnerView().setText(playerName);
	}

	@Override
	public void setTribe(Tribe tribe) {
		getTribeView().setText(tribe.name());
		getAllianceImageView().setImageResource(resourceMapper.getResourceFor(tribe));
	}

	@Override
	public void setAllianceName(String allianceName) {
		getAllianceView().setText(allianceName);
	}

	@Override
	public void setCoords(int x, int y) {
		getCoordsView().setText("(" + x + ", " + y + ")");
	}

	@Override
	public void setOnPlayerClickListener(OnClickListener clickListener) {
		getOwnerLabelView().setOnClickListener(clickListener);
		getOwnerView().setOnClickListener(clickListener);
	}

	private TextView getVillageView() {
		return (TextView) root.findViewById(R.id.villageDetailsVillageName);
	}

	private TextView getPopulationView() {
		return (TextView) root.findViewById(R.id.villageDetailsPopulation);
	}

	private TextView getOwnerView() {
		return (TextView) root.findViewById(R.id.villageDetailsOwner);
	}

	private ImageView getAllianceImageView() {
		return (ImageView) root.findViewById(R.id.villageDetailsVillageIcon);
	}

	private TextView getAllianceView() {
		return (TextView) root.findViewById(R.id.villageDetailsAlliance);
	}

	private TextView getTribeView() {
		return (TextView) root.findViewById(R.id.villageDetailsTribe);
	}

	private TextView getCoordsView() {
		return (TextView) root.findViewById(R.id.villageDetailsCoords);
	}

	private TextView getOwnerLabelView() {
		return (TextView) root.findViewById(R.id.villageDetailsOwnerLabel);
	}
}
